<template>
  <div>
    <el-dialog
      :title="detail.name"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <div>
        <el-form ref="form" :model="form" label-width="100px">
          <el-form-item label="心跳频率">
            <el-input v-model="form.heartbeat_frequency" style="width: 80%"></el-input> s/次
          </el-form-item>
          <el-form-item label="麦位刷新频率">
            <el-input v-model="form.refresh_frequency" style="width: 80%"></el-input> s/次
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('update:dialogVisible', false)">取 消</el-button>
        <el-button type="primary" @click="editSubmitClick">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { appSettingEdit, getVersionNumber } from '../../../../api/config/listVersion'

export default {
  name: "editConfigVersion",
  props: {
    dialogVisible: {
      type: Boolean,
      default() {
        return false
      }
    },
    detail: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      form: {
        heartbeat_frequency: null,
        refresh_frequency: null
      }
    };
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          this.$emit('update:dialogVisible', false)
        })
        .catch(_ => {});
    },
    /**
     * editSubmitClick
     * @desc 点击提交按钮
     */
    async editSubmitClick() {
      let data = {
        app_type: this.detail.app_type,
        name: this.detail.name,
        heartbeat_frequency: this.form.heartbeat_frequency,
        refresh_frequency: this.form.refresh_frequency
      }
      if (this.detail.heartbeat_frequency === this.form.heartbeat_frequency && this.form.refresh_frequency === this.detail.refresh_frequency) {
        this.$emit('update:dialogVisible', false)
      } else {
        const detail = await appSettingEdit(this.detail.id, data)
        if (detail.data) {
          this.$message.success('修改成功')
          this.$emit('update:dialogVisible', false)
          this.$emit('upadeteConfig')
        }
      }
    }
  },
  watch: {
    detail: {
      deep: true,
      handler(newVal, oldVal) {
        this.form = Object.assign(this.form, newVal)
      }
    }
  }
}
</script>

<style scoped lang="scss">

</style>
